package com.tre.jdevtemplateboot.web.controller;

import com.tre.jdevtemplateboot.common.dto.ResponseResult;
import com.tre.jdevtemplateboot.domain.dto.SpAppFunctionMstDto;
import com.tre.jdevtemplateboot.domain.vo.SpAppFunctionMstVO;
import com.tre.jdevtemplateboot.domain.vo.SpAppMstListVO;
import com.tre.jdevtemplateboot.service.ISpAppFunctionMstService;
import com.tre.jdevtemplateboot.service.ISpAppMstService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author meng
 * @version 1.0
 * @description: 功能设定控制器
 * @date 2023/11/10 21:01
 */
@RestController
@RequestMapping("/function")
public class SpFunctionController {

    @Autowired
    private ISpAppFunctionMstService spAppFunctionMstService;

    @Autowired
    private ISpAppMstService spAppMstService;

    @GetMapping("/app/{id}")
    public ResponseResult<SpAppFunctionMstVO> list(@PathVariable String appId){
        return spAppFunctionMstService.findALl(appId);
    }

    @PostMapping("/save")
    public ResponseResult save(@RequestBody SpAppFunctionMstDto dto){
        return spAppFunctionMstService.saveFunction(dto);
    }

    @PutMapping("/update")
    public ResponseResult update(@RequestBody SpAppFunctionMstDto dto){
        return spAppFunctionMstService.updateFunction(dto);
    }

    @GetMapping("/findById/{id}")
    public ResponseResult<SpAppFunctionMstVO> findById(@PathVariable String id){
        return spAppFunctionMstService.findById(id);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult removeById(@PathVariable String id){
        spAppFunctionMstService.removeById(id);
        return ResponseResult.buildOK();
    }

    @GetMapping("/list")
    public ResponseResult<SpAppMstListVO> findAppList(){
        return spAppMstService.findAll();
    }

    @GetMapping("/parent/{parentId}")
    public ResponseResult<List<SpAppFunctionMstVO>> findByParentId(@PathVariable String parentId){
        return spAppFunctionMstService.findByParentId(parentId);
    }

}
